//
//  ObserverPatternTest.m
//  DesignPattern
//
//  Created by 管理员 on 2019/1/8.
//  Copyright © 2019年 Alic. All rights reserved.
//

#import "ObserverPatternTest.h"
#import "SubscriptionServiceCenter.h"

static NSString *scienceA = @"scienceA";

static NSString *scienceB = @"scienceB";

static NSString *versionA = @"version1.0.0";

static NSString *versionB = @"version2.0.0";

@implementation ObserverPatternTest

-(void)test{
    
    //创建刊物
    [SubscriptionServiceCenter createSubscriptionNumber:scienceA];
    [SubscriptionServiceCenter createSubscriptionNumber:scienceB];
    
    //创建消费者
    Customer *customerA = [[Customer alloc] initWithName:@"customerA"];
    Customer *customerB = [[Customer alloc] initWithName:@"customerB"];
    
    
    //消费者A 订阅了 刊物A
    [SubscriptionServiceCenter addCustomer:customerA withSubscriptionNumber:scienceA];
    
    //消费者B 订阅了 刊物A+刊物B
    [SubscriptionServiceCenter addCustomer:customerB withSubscriptionNumber:scienceA];
    [SubscriptionServiceCenter addCustomer:customerB withSubscriptionNumber:scienceB];
    
    
    //刊物A 有新版本发行
    [SubscriptionServiceCenter sendMessage:versionA toSubscriptionNumber:scienceA];
    
    //刊物B 有新版本发行
    [SubscriptionServiceCenter sendMessage:versionB toSubscriptionNumber:scienceB];
    
    //消费者A 应该接收到 刊物A 的更新信息
    //消费者B 应该同时接收到 刊物A+刊物B 的更新信息
    
    //    以下是我的打印信息，正好符合我的设计图的构思，请注意观看
    //    2017-02-20 23:37:41.537 ObserverPattern[2676:85820] version1.0.0 scienceA wupengA
    //    2017-02-20 23:37:41.538 ObserverPattern[2676:85820] version1.0.0 scienceA wupengB
    //    2017-02-20 23:37:41.538 ObserverPattern[2676:85820] version2.0.0 scienceB wupengB
    
    
}

@end
